package com.wande.dataplatform.filecollection.common.exception;

import com.wande.dataplatform.filecollection.common.enums.FileCollectionErrorCode;

/**
 * 文件采集模块自定义异常
 *
 * @author wande
 */
public class FileCollectionException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private final int code;

    /**
     * 错误消息
     */
    private final String message;

    public FileCollectionException(FileCollectionErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }

    public FileCollectionException(FileCollectionErrorCode errorCode, String detailMessage) {
        super(errorCode.getMessage() + ": " + detailMessage);
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage() + ": " + detailMessage;
    }

    public FileCollectionException(FileCollectionErrorCode errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }

    public FileCollectionException(FileCollectionErrorCode errorCode, String detailMessage, Throwable cause) {
        super(errorCode.getMessage() + ": " + detailMessage, cause);
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage() + ": " + detailMessage;
    }

    public FileCollectionException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public FileCollectionException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
